cd "~/Dropbox/Shared Folder - J. Ladd & M (1). Meredith/Replication Files/"
cap log close
log using "LogFiles/TableA5.log", replace

clear all
set more off

matrix Results = J(16, 11, 0)

use "RawData/GallupDataBJPS.dta", clear
// Drops Unrepresentative Series
drop if drops == "All" | regexm(drops, "Ideology")
// Drops Obs. w/o Party ID
drop if ideo == -9 | ideo == -99

// Sets the Survey Date as the Mid-Point in Field
gen middle_date = .
replace middle_date = floor((start_date + end_date) / 2)
gen quarter = qofd(middle_date)
format quarter %tq

levelsof quarter, local (fourths) 

foreach i of local fourths {
local counter = `i' - 128
local year = 1992 + floor(`counter' / 4)
tab series if quarter == `i'
local row = 1 + mod(`counter', 4)*2 + floor((`year' - 1992) / 11)*8
local column = 1 + mod((`year' - 1992), 11)
matrix Results[`row', `column'] = r(N)
matrix Results[`row'+1, `column'] = -r(r)
}

matlist Results

log close
